<template>
  <div class="main-content">
    <div class="header mb-4">
      <div class="container-fluid">
        <!-- Body -->
        <div class="header-body border-bottom py-4">
          <div class="row align-items-end">
            <div class="col">
              <!-- Title -->
              <h2 class="header-title">
                Jupiter 项目生成
              </h2>
            </div>
            <div class="col-auto">
            </div>
          </div> <!-- / .row -->
        </div> <!-- / .header-body -->

      </div>
    </div>
    <div class="container px-4">

      <div class="mb-3">
        <label for="dir">作者/Author</label>
        <input type="text" class="form-control" v-model="formData.author" >
      </div>


      <div class="mb-3">
        <label for="dir">项目的父目录</label>
        <input type="text" class="form-control" id="dir" v-model="formData.dir" >
      </div>

      <div class="mb-3">
        <label for="name">项目的名称 </label>
        <input type="text" class="form-control" id="name" v-model="formData.name" placeholder="建议首字母大写的单词加横杠如: Jupiter-Server">
      </div>

      <div class="mb-3">
        <label for="name">项目的包名 </label>
        <input type="text" class="form-control" id="package" v-model="formData.packageName" placeholder="如: com.edgardeng">
      </div>

      <div class="mb-3">
        <label for="desc">项目的描述 </label>
        <input type="text" class="form-control" id="desc" v-model="formData.desc">
      </div>

      <div class="mt-5">
        <button type="button" class="btn btn-primary btn-sm" @click="submit"> 生成项目
        </button>
      </div>
    </div>
  </div>
</template>
<script>
  module.exports = {
    name: 'GeneratorProject',
    data() {
      return {
        searchName: '',
        formData: {
          author: "Edgar Deng (https://edgardeng.github.io)",
          dir: "/Users/edgar/workspace",
          name: "Jupiter-Admin", // limit item size in a page
          desc: "Jupiter是一个基于Spring Boot和Spring Cloud开发的后台管理系统",
          packageName: "com.edgardeng"
        },
      }
    },
    created () {
      let item = window.localStorage.getItem("generator.project")
      if (!item || item === 'undefined') {
        return
      }
      let result = JSON.parse(item)
      this.formData.author = result.author
      this.formData.dir = result.dir
      this.formData.name = result.name
      this.formData.desc = result.desc
      this.formData.packageName = result.packageName
    },
    methods: {
      submit() {
        // 保存参数 下次使用
        window.localStorage.setItem("generator.project", JSON.stringify(this.formData))
        this.$emit('generate', this.formData)
      }
    }
  }
</script>
